<template>
  <div class="SignIn">
    <div class="SignIn-kuan">
      <div class="SignIn-text-one">账号登录</div>
      <div class="SignIn-text-two">
        <div class="two-text">手机号：</div>
        <input
          type="text"
          onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"
          :placeholder="valueOne"
          v-model="valueOne"
          @focus="SignInfocus(valueOne)"
          @blur="SignInblur(valueOne)"
        />
      </div>
      <div class="SignIn-text-three">
        <div class="three-text">密码：</div>
        <!-- <input type="password" name="" id=""> -->
        <input
          :type="xiugai"
          onkeyup="value=value.replace(/[^\w\.\/]/ig,'')"
          :placeholder="valueTwo"
          v-model="valueTwo"
          @focus="SignInfocus(valueTwo)"
          @blur="SignInblur(valueTwo)"
        />
        <div class="three-icon">
          <van-icon :name="nameIcon" @click="Iconhuan" />
        </div>
      </div>
      <div class="SignIn-text-four">
        <button class="four-text-one" @click="home()">登录</button>
        <button class="four-text-two" @click="Register()">注册</button>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  name: "SignIn",
  data() {
    return {
      xiugai: "text",
      // xiugai: "password",
      valueOne: "请输入手机号",
      valueTwo: "请输入密码",
      name: "",
      CellPhoneNumber: "",
      password: "",
      nameIcon: "eye-o",
    };
  },
  created() {
    this.get();
  },
  methods: {
    Iconhuan() {
      if (this.xiugai == "password") {
        this.xiugai = "text";
        this.nameIcon = "eye";
      } else {
        this.xiugai = "password";
        this.nameIcon = "eye-o";
      }
    },
    get() {
      this.name = this.$store.state.name;
      this.CellPhoneNumber = this.$store.state.CellPhoneNumber;
      this.password = this.$store.state.password;
      // console.log('this.name==>',this.name);
      // console.log('this.CellPhoneNumber==>',this.CellPhoneNumber);
      // console.log('this.password==>',this.password);
      // console.log('this.ifEavr==>',this.ifEavr);
    },
    home() {
      // console.log(this.valueOne);
      if (this.valueOne == "请输入手机号") {
        Toast("请输入用户名!!!");
      } else if (this.valueTwo == "请输入密码") {
        Toast("请输入密码!!!");
      } else if (
        this.valueTwo !== this.password ||
        this.valueOne !== this.CellPhoneNumber
      ) {
        Toast("密码或手机号错误!!!");
      } else if (this.valueTwo == this.password) {
        if (this.valueOne == this.CellPhoneNumber) {
          Toast("登录成功！！！");
          this.$store.state.ifEavr = true;
          this.$store.state.ifEavrOne = false;
          this.$router.push({ name: "Home" });
        }
      }
    },
    Register() {
      this.$router.push({ name: "Register" });
    },
    SignInfocus(val) {
      if (this.valueOne == val) {
        this.valueOne = "";
      } else if (this.valueTwo == val) {
        this.valueTwo = "";
        this.xiugai = "password";
        this.nameIcon = "eye-o";
      }
    },
    SignInblur() {
      if (this.valueOne == "") {
        this.valueOne = "请输入手机号";
      } else if (this.valueTwo == "") {
        this.valueTwo = "请输入密码";
        this.xiugai = "text";
        this.nameIcon = "eye-o";
      }
    },
  },
};
</script>

<style lang="less" scoped>
.SignIn {
  width: 950px;
  height: 400px;
  padding-top: 100px;
  .SignIn-kuan {
    width: 340px;
    height: 260px;
    margin: 0 auto;
    padding: 20px 30px;
    border-radius: 15px;
    border: 1px solid rgb(148, 148, 148);
    background-color: white;
    .SignIn-text-one {
      width: 100%;
      height: 60px;
      font-size: 19px;
      text-align: center;
      line-height: 60px;
    }
    input {
      float: left;
      width: 245px;
      height: 30px;
      margin-top: 5px;
      font-size: 13px;
      padding-left: 10px;
      color: rgb(119, 119, 119);
    }
    .SignIn-text-two {
      width: 100%;
      height: 40px;
      padding: 5px 0;
      .two-text {
        float: left;
        width: 60px;
        height: 40px;
        padding-left: 15px;
        font-size: 13px;
        line-height: 40px;
      }
    }
    .SignIn-text-three {
      width: 100%;
      height: 40px;
      padding: 5px 0;
      position: relative;
      .three-text {
        float: left;
        width: 60px;
        height: 40px;
        padding-left: 15px;
        font-size: 13px;
        line-height: 40px;
      }
      .three-icon {
        width: 20px;
        height: 20px;
        position: absolute;
        top: 18px;
        right: 15px;
        font-size: 16px;
        text-align: center;
        line-height: 20px;
        cursor: pointer;
      }
    }
    .SignIn-text-four {
      width: 100%;
      height: 40px;
      padding: 5px 0;
      .four-text-one {
        float: left;
        width: 155px;
        height: 40px;
        font-size: 13px;
        line-height: 40px;
        cursor: pointer;
        border: 0;
        border-radius: 5px;
        margin-left: 10px;
      }
      .four-text-one:hover {
        background-color: rgb(216, 216, 216);
      }
      .four-text-two {
        float: right;
        width: 155px;
        height: 40px;
        font-size: 13px;
        line-height: 40px;
        cursor: pointer;
        border: 0;
        margin-right: 10px;
        border-radius: 5px;
        background-color: aqua;
      }
      .four-text-two:hover {
        background-color: rgb(0, 233, 233);
      }
    }
  }
}
</style>